
#define USEAC3kR

#include <iostream>
#include <sstream> // for integer -> string
#include <fstream>
#include <string> 

using namespace std;

// void batchTable(int argc, char *argv[])
int main(int argc, char *argv[])
{

#ifdef USEAC3kR
  if (argc != 5) {
    cerr << "usage: -b residueCacheSize residueMethod" << endl;
    return -1;
  }

  string problemSets(argv[2]);

  cout << "The problem sets file is " << problemSets << endl;

  int cacheSize = atoi(argv[3]);
  int method = atoi(argv[4]);
#endif

  float averageCChecks = 0;
  float averageDChecks = 0;

  // for k-residue
  float averageOChecks = 0;
  float averageBacktracks = 0;
  float averageMaxSearchDepth = 0;
  
  string consumeNL;

  //  ResourcesUsageCounter clock, clock1;

  ifstream configure(problemSets.c_str());

  if(!configure) {
    cerr << "The configuration experiment.conf does not exist" << endl;
    exit (-1);
  }

  string directory;

  // get the directory of the experimental files
  while (! configure.eof()){
    configure >> directory;
    // skip the comments and empty lines
    if (directory.empty() || directory[0] == '%'){
      getline(configure, consumeNL); 
      continue;
    }
    else break;
  }

  // get the directory
  
  if (directory.empty() || directory != "directory"){
    cerr << "directory should be the first effective line in experiment.conf" << endl;
    exit (-1);
  }
  else {
    configure >> directory; // get the directory
    getline(configure, consumeNL);
  }
 
  while(!configure.eof()){
    string f1, f2;
    int start, end;
    int averagePerformance;

    configure >> f1;

    // skip comments and empty lines
    if (f1.empty() || f1[0] == '%'){
      getline(configure, consumeNL); 
      continue;
    }

    configure >> f2;
    configure >> averagePerformance; 
    configure >> start;
    configure >> end;
 
    // skip the rest of the line
    getline(configure, consumeNL);

    cout << "file:" << f1 << '?' << f2 << endl;
    cout << "start:" << start << ' '
	 << "end:" << end << endl;
     
    for(int instance = start; instance <= end; instance++) {
      string fileName;
      ostringstream str;
      
      str << instance; 
      fileName = directory + f1 + str.str() + f2;
 
      // cout << "file:" << fileName << endl;
      // getline(cin, consumeNL);

      ifstream instanceFile;
      instanceFile.open(fileName.c_str());
      if (! instanceFile) {
	cerr << "The file " << fileName << "does not exist." << endl;
	continue; // process the next file
      }
      /*
	1. BT csp(instanceFile) -- file object or name? 
	2. csp.solve()
	3. if (averagePerformance) {
	4.    average the performance
	5  }
	6. else output the performance 
      */

    } // process the files from start to end
   
  } // 
}
